import Express from "express";

import BackCode from "../../utils/backCode";
import { login } from "../../severs/adminUser";
import { createToken } from "../../plugins/jwt";
const router: any = Express.Router();
router.post("/", function (req: any, res: any, next: any) {
  const { username, password } = req.body;
  login({ username, password })
    .then((user) => {
      const token = createToken({
        id: user.id,
        bgm: "fjjjf",
      });
      const data = BackCode.buildSuccessAndData({
        id: user.id,
        token,
      });
      res.send(data);
    })
    .catch((err) => {});

  // res.render("index", { title: "Express" });
});

router.post("/register", function (req: any, res: any, next: any) {
  const { username, password } = req.body;
  const sql = `select *`;
  console.log("收到了信息");
  console.log(req.body);
  const data = BackCode.buildSuccessAndData(req.body);
  res.send(data);
  // res.render("index", { title: "Express" });
});

export default router;
